
#include "../UdpSocket.h"
#include <stdlib.h>
#include <string.h>

const int SOCKETTIMEOUT=2000;
const int BUFFSIZE=1024;
int main()
{
	int clientPort=0;
	UdpSocket *s=new UdpSocket();
	char buf[BUFFSIZE];
	memset(buf,0,sizeof(buf));

	bool isBind=s->bindPort(12345);
	while (isBind)
	{
		if(s->recvData(buf,sizeof(buf),0)>0) //block
		//if(s->recvData(buf,sizeof(buf),SOCKETTIMEOUT)>0) //no block
		{
			printf("recv %s from:ip:%s, port:%d\n",buf,s->socketIP(),s->socketPort());
		}
		if( strlen(buf)>0 )
		{
			int ret=s->sendData(buf,sizeof(buf),s->socketIP(),s->socketPort(), SOCKETTIMEOUT);//no block
			//int ret=s->sendData(buf,sizeof(buf),s->socketIP(),s->socketPort(), 0);//block
			if(ret>0)
			{
				printf("sent: %s\n",buf);
			}
			memset(buf,0,sizeof(buf));
		}
	}
	s->closeUdpSocket();
	delete s;
	getchar();
	return 0;
}

